<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>授权处理中</title>
    <style>
        body {
            font-family: 'Microsoft YaHei', sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background: #f5f5f5;
        }

        .container {
            text-align: center;
            background: white;
            padding: 40px;
            border-radius: 10px;
            box-shadow: 0 4px 15px rgba(0,0,0,0.1);
            max-width: 400px;
            width: 90%;
        }

        .spinner {
            border: 4px solid #f3f3f3;
            border-top: 4px solid #07c160;
            border-radius: 50%;
            width: 40px;
            height: 40px;
            animation: spin 1s linear infinite;
            margin: 0 auto 20px;
        }

        @keyframes spin {
            0% {
                transform: rotate(0deg);
            }

            100% {
                transform: rotate(360deg);
            }
        }

        .success {
            color: #07c160;
        }

        .error {
            color: #e74c3c;
        }

        .hidden {
            display: none;
        }

        .btn {
            background: #07c160;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            margin-top: 15px;
        }

        .btn-secondary {
            background: #6c757d;
            margin-left: 10px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div id="loading">
            <div class="spinner"></div>
            <p>正在处理微信授权...</p>
        </div>

        <div id="success" class="hidden success">
            <h3>🎉 授权成功！</h3>
            <p>正在跳转回原页面...</p>
        </div>

        <div id="error" class="hidden error">
            <h3>❌ 授权失败</h3>
            <p id="errorMessage">授权处理过程中出现错误</p>
            <div style="margin-top: 20px;">
                <button onclick="retryAuth()" class="btn">重新授权</button>
                <button onclick="goHome()" class="btn btn-secondary">返回首页</button>
            </div>
        </div>
    </div>

    <script>
        async function handleAuthCallback() {
            const urlParams = new URLSearchParams(window.location.search);
            const code = urlParams.get('code');
            const state = urlParams.get('state');
            const pageid = urlParams.get('pageid');


            console.log('授权回调参数:', { code, state });

            console.log('pageid:', { pageid });
            console.log('urlParams:', { urlParams });



            if (!pageid) {
                
            }

 
        }

        function showSuccess() {
            document.getElementById('loading').classList.add('hidden');
            document.getElementById('success').classList.remove('hidden');
        }

        function showError(message) {
            document.getElementById('loading').classList.add('hidden');
            document.getElementById('error').classList.remove('hidden');
            document.getElementById('errorMessage').textContent = message;
        }

        function retryAuth() {
            // 重新跳转到首页进行授权
            window.location.href = '/';
        }

        function goHome() {
            window.location.href = '/';
        }

        // 页面加载完成后处理回调
        window.addEventListener('load', handleAuthCallback);

        // 添加错误监听
        window.addEventListener('error', function (event) {
            console.error('页面错误:', event.error);
        });
    </script>
</body>
</html>